import opendap.dap.AttributeTable;
import opendap.dap.BaseType;
import opendap.dap.DAS;
import opendap.dap.DConnect2;
import opendap.dap.DDS;
import opendap.dap.StatusUI;

import java.util.Enumeration;
import java.util.Scanner;
import opendap.util.geturl.gui.*;

public class TestDap {

	public static void main(String[] args)
	{
//		http://test.opendap.org/dap/data/nc/sst.mnmean.nc.gz
		
		try{
			Scanner input = new Scanner(System.in);
			
			System.out.print("Enter Data URL:");
			String url = input.nextLine();
			
			DConnect2 dc = new DConnect2(url);
			
	
			
			
			System.out.println("");
	        System.out.println("");
	        System.out.println("########################################################");
	        System.out.println("\nConnecting to " + url + "\n");
	
	

	        System.out.println("\n- - - - - - - - - - - - - - - - - - -");
	
	        System.out.println("Retrieving DDS:\n");
	        DDS dds = dc.getDDS();
	        dds.print(System.out);
		    
	        
	        //AttributeTable attTable = dds.getAttributeTable();
	        
	        //System.out.println("Attribute table names:\n");
	        
//	        for(Enumeration e = attTable.getNames(); e.hasMoreElements();)
//	        {
//	        	System.out.println((String) e.nextElement());
//	        	
//	        }
	        System.out.println("Variables:\n");
	        for(Enumeration e = dds.getVariables(); e.hasMoreElements();)
	        {
	        	
	        	//System.out.println(e.nextElement().toString());
	        	BaseType bt = (BaseType) e.nextElement();
	        	System.out.print("varName: " + bt.getName() + "   varType: " + bt.getTypeName() + "\n");
	        	
	        	
	        }
	        
	        
	               
	        System.out.println("\n- - - - - - - - - - - - - - - - - - -");
	        System.out.println("Retrieving DAS:\n");
	        DAS das = dc.getDAS();
	        das.print(System.out);

//	        System.out.println("\n- - - - - - - - - - - - - - - - - - -");
//	        System.out.println("Retrieving DDX:\n");
//	        dds = dc.getDDX();
//	        dds.printXML(System.out);
	
	        StatusWindow sw = new StatusWindow(url);
	        
	        //How do we get the cancel status??
	        
	        System.out.println("\n- - - - - - - - - - - - - - - - - - -");
	        System.out.println("Retrieving DATA:\n");
	        //dds = dc.getData("");
	        dds = dc.getData("",sw);
	        dds.printVal(System.out, "");	        	

	        //DataDDS data = dc.getData("", sw);
	        
	        
				           
			
			input.close();
		}
		catch(Throwable t) {
            t.printStackTrace(System.err);
			
		}
		
		
	}
	

}
